package app.models;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import app.models.enums.TipoConsulta;

/**
 * @author Douglas Fernandes
 * @since 22/11/2013
 */

@Entity
@Table(name = "PACIENTE")
public class Paciente implements Pojo {
	
	private static final long serialVersionUID = 3663026546076423791L;
	
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID")
	private Long id;
	
	@NotNull(message = "O tipo padrão das Consultas deve ser preenchido")
	@Column(name = "TIPO", columnDefinition = "varchar(30)")
	@Enumerated(EnumType.STRING)
	private TipoConsulta tipo;
	
	@Column(name = "ID_CONVENIO")
	private Integer idConvenio;
	
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ID_CONVENIO", referencedColumnName = "ID", insertable = false, updatable = false)
	private Convenio convenio;
	
	@NotNull(message = "O usuario deve ser preenchido")
	@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@JoinColumn(name = "ID_USUARIO", referencedColumnName = "ID", insertable = true, updatable = true)
	private Usuario usuario;
	
	@Column(name = "NUM_CARTEIRA", columnDefinition = "varchar(50)")
	private String numCarteira;
	
	@Column(name = "NOME_PAI", columnDefinition = "varchar(200)")
	private String nomePai;
	
	@Column(name = "NOME_MAE", columnDefinition = "varchar(200)")
	private String nomeMae;
	
	@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@JoinColumn(name = "ID_BIOMETRIA", referencedColumnName = "ID", insertable = false, updatable = false)
	private BiometriaTemplate biometria;
	
	@Column(name = "ID_BIOMETRIA", columnDefinition = "integer")
	private Integer idBiometria;
	
	
	public void setId(Long id) {
		this.id = id;
	}

	public Long getId() {
		return id;
	}
	
	public TipoConsulta getTipo() {
		return tipo;
	}

	public void setTipo(TipoConsulta tipo) {
		this.tipo = tipo;
	}

	public BiometriaTemplate getBiometria() {
		return biometria;
	}

	public void setBiometria(BiometriaTemplate biometria) {
		this.biometria = biometria;
	}

	public Integer getIdBiometria() {
		return idBiometria;
	}

	public void setIdBiometria(Integer idBiometria) {
		this.idBiometria = idBiometria;
	}

	public Integer getIdConvenio() {
		return idConvenio;
	}

	public void setIdConvenio(Integer idConvenio) {
		this.idConvenio = idConvenio;
	}

	public void setConvenio(Convenio convenio) {
		this.convenio = convenio;
	}

	public Convenio getConvenio() {
		return convenio;
	}

	public void setNumCarteira(String numCarteira) {
		this.numCarteira = numCarteira;
	}

	public String getNumCarteira() {
		return numCarteira;
	}

	public Usuario getUsuario() {
		return usuario;
	}

	public void setUsuario(Usuario usuario) {
		this.usuario = usuario;
	}

	public String getNomePai() {
		return nomePai;
	}

	public void setNomePai(String nomePai) {
		this.nomePai = nomePai;
	}

	public String getNomeMae() {
		return nomeMae;
	}

	public void setNomeMae(String nomeMae) {
		this.nomeMae = nomeMae;
	}
	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Paciente other = (Paciente) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

}
